package org.shj.hadoop.customerinputformat;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.FloatWritable;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.GenericOptionsParser;

import com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider.Text;

public class MapReducerDriver {

	public static void main(String[] args) throws Exception{
		Configuration conf = new Configuration();
		String[] paths = {"hdfs://192.168.56.101:9000/user/sj/output"};
		String[] otherArgs = new GenericOptionsParser(conf, paths).getRemainingArgs();
		
		if(otherArgs.length != 1){
			System.err.println("Usage: FindMaxValue <OutputDir");
		}
		
		conf.set("NumOfValues", "111");
		conf.set("hadoop.job.ugi", "shj,shj");
//		conf.set("mapred.system.dir", "/home/shj/hadoop");
		
		Job job = Job.getInstance(conf, "FindMaxValue");
		job.setJarByClass(MapReducerDriver.class);
		job.setMapperClass(FindMaxValueMapper.class);
		job.setReducerClass(FindMaxValueReduce.class);
		job.setMapOutputKeyClass(IntWritable.class);
		job.setMapOutputValueClass(FloatWritable.class);
		
		job.setOutputKeyClass(Text.class);
		job.setOutputValueClass(FloatWritable.class);
		
		job.setInputFormatClass(FindMaxValueInputFormat.class);
		FileOutputFormat.setOutputPath(job, new Path(otherArgs[0]));
		
		System.out.println(conf.get("mapred.job.tracker"));
		System.exit(job.waitForCompletion(true) ? 0 : 1);
	}
}
